package com.th.therp.config;

import com.th.therp.interceptor.JwtTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration  // 标注此类为配置类，用于配置 Spring MVC
public class WebConfig implements WebMvcConfigurer {

    @Autowired  // 自动注入自定义的拦截器
    private JwtTokenInterceptor jwtTokenInterceptor;

    // 覆盖 addInterceptors 方法，添加自定义拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册自定义拦截器
        registry.addInterceptor(jwtTokenInterceptor)
                .addPathPatterns("/**")  // 拦截所有请求路径
                .excludePathPatterns("/user/login", "/user/register","/user/sendCode");  // 排除 login 和 register 请求路径，不进行拦截
    }
}
